﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;

/// <summary>
/// Summary description for root_level
/// </summary>
/// 
namespace Bestlife.ERP.BusinessRules
{

    public class root_level
    {
        SqlDataReader rdR;
        List<String>getchilds =new List<string>();
        String levelcount;
        public root_level()
        {
            //
            // TODO: Add constructor logic here
            //
        }


        //public day26()
        //{

        //    //String 


        //}


        

        public String root_levelID()
        {
           
            String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
            Bestlife.ERP.DataAccess.clsCon.connect(connStr);

            String Ssql = "SELECT User_id,Parent_To_User FROM  Distributor_Level WHERE  Parent_To_User=(SELECT MAX(Parent_To_User) FROM Distributor_Level)";

            rdR = DataAccess.clsCon.ReadTable(Ssql);


            while (rdR.Read())
            {
                levelcount = rdR["Parent_To_User"].ToString();           
            }

            rdR.Close();

            return  levelcount;


        }// public root level count


        public List<String> Get_root_levelID(String LevelID)
        {
            String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
            Bestlife.ERP.DataAccess.clsCon.connect(connStr);

            String Ssql = "SELECT User_id,Parent_To_User FROM   Distributor_Level WHERE  Parent_To_User='"+LevelID+"'";

            rdR = DataAccess.clsCon.ReadTable(Ssql);


            while (rdR.Read())
            {
               String userId = rdR["User_id"].ToString();

                getchilds.Add(userId);
            
            }

            rdR.Close();

            return getchilds;


        }// public root level


    }
}